<template>
  <div class='table'>
    <ui-container>
      <div style="font-size:12px;padding-left:15px;color:#999;margin-top:10px;">
      </div>
      <div class="rows">
        <div class="label">新密码:</div>
        <div>
          <el-input
            placeholder=""
            type="password"
            v-model="newPwd"
            size="small"
            clearable style="width:300px">
          </el-input>
        </div>
         <div>
          <el-button type="primary" size="small" @click="save()">保存</el-button>
        </div>
      </div>
    </ui-container>
  </div>
</template>
<script type='text/javascript'>
import {mapGetters, mapActions} from 'vuex'
import {SET_USER_INFO} from 'src/store/actions/type'
import {UserLogin} from 'src/router/auto-routes'
export default {
  name: 'IntegralTransfor',
  data () {
    return {
      newPwd: '',
    }
  },
  mounted () {
    this.init();
  },
  methods: {
    init(){
    },
    ...mapActions({
      setUserInfo: SET_USER_INFO
    }),
    async save(){
        if(this.newPwd === null || this.newPwd.length ===0){
            this.$message({
                type: 'error',
                message: '新密码不能为空！'
            });
            return;
        }
        var params = {
            newPwd: this.newPwd
        };
        const {$confirm, $api, $message, $router, setUserInfo} = this
        try {
            await $confirm('此操作将修改管理员密码, 修改成功后系统将退出登录, 是否继续?', '提示', {type: 'warning'})
            this.$api.user.updateAdminPassword(params).then((rs) => {
                if(rs.IsSuccess){
                    this.$message({
                        type: 'success',
                        message: '设置成功，管理员需要重新登录!'
                    });
                    setUserInfo(null)
                    $router.replace(UserLogin.path)
                }
            }).catch((res) =>{})
        } catch ({msg}) {
        msg && $message.warn(msg)
      }
    }
  }
}
</script>
<style lang='scss' type='text/scss' rel='stylesheet/scss' scope>
.container-main{
  width: 100% !important;
}
.rows {
  font-size: 14px;
  color: #666;
  margin: 15px 0;
  display: flex;
  align-items: center;
  .label{
    width: 280px;
    text-align: right;
    margin-right: 10px;
  }
  button {
    margin-left: 10px;
  }
}
</style>